<template lang="html">
  <div class="">
    <backheader ref="header"></backheader>
    <section class="book-info-section" :style="{'margin-top':top}">
      <div class="book-detail">
          <img :src="cover"  class="book-cover fl">
          <div class="book-desc">
              <h2 class="book-title">{{data.title}}</h2>
              <p class="book-meta red">{{data.author}}</p>
              <p class="book-meta">{{ data.majorCate }}/{{ data.minorCate }}</p>
              <p class="book-meta">{{wordCount}}<span class="split-line">|</span> {{ data.isSerial ? '连载中' : '完结'}}</p>
          </div>
      </div>
      <div class="book-reader">
          <p class="reader-item"><span class="title">追人气</span><span class="content">{{ data.latelyFollower }}</span></p>
          <p class="reader-item"><span class="title">读者留存率</span><span class="content">{{ data.retentionRatio }}%</span></p>
          <p class="reader-item"><span class="title">日更新字数/天</span><span class="content">{{ serializeWordCount }}</span></p>
      </div>
      <div class="book-intro part">
          <p class="long-intro">{{data.longIntro}}</p>
      </div>
      <div class="book-menu">
          <a href="javascript:" class="" @click="menu(data._id)">
              <div class="menu-title fl">目录</div>
              <p class="menu-content fr gray">2015-11-04<span class="split-dot">·</span> {{ data.lastChapter }}
              </p>
          </a>
      </div>
    </section>
    <section class="review">
        <h2>热门书评</h2>
        <ul class="review-list">
            <li class="review-item" v-for="review in reviews.reviews"  ><img :src="review.author.avatar | setAvatar" :alt="review.author.nickname" class="avatar">
                <div class="review-content">
                    <p class="name">{{ review.author.nickname }}<span class="time fr">{{ review.updated |time }}</span></p>
                    <p class="title">{{review.title}}</p>
                    <p class="content text-line-comm">{{review.content}}</p>
                </div>
            </li>



        </ul>
    </section>
    <section class="recommend">
        <h4>同类推荐
                <a href="javascript:" class="more red" @click="more()">更多</a>
        </h4>
        <ul class="recommend-list">
                <li class="recommend-item" v-for="item in recommend.books"  @click="toBook(item._id);">
                        <img :src="item.cover | cover" alt="item.title" class="cover">
                        <p>{{item.title}}</p>
                </li>
        </ul>
    </section>
    <section class="book-bar">
        <div class="book-bar-item read">
            <a href="javascript:" @click="readNow()">
                <p class="book-bar-content">立即阅读</p>
            </a>
        </div>
    </section>
  </div>
</template>

<script>
import backheader from '@/components/backheader';
export default {
  data(){
    return {
      data:'',
      reviews:'',
      recommend:''
    }
  },
  methods:{
    readNow(){
      let id = this.$route.params.id;
      this.axios('http://127.0.0.1:4000/data/get_chapter_id?id='+id).then((res) => {
        var chapterId=res.data.chapters[0].id;
        this.$router.push({path:"/reader/id/"+id+"/book/"+chapterId});
      });
    }
  },
  computed:{
    cover() {
      return "http://statics.zhuishushenqi.com" + this.data.cover;
    },
    wordCount() {
      return this.data.wordCount > 10000 ? parseInt(this.data.wordCount / 10000) + '万' : this.data.wordCount;
    },
    serializeWordCount() {
      return this.data.serializeWordCount < 0 ? 0 : this.data.serializeWordCount;
    },
    top(){
      return "50px";
    }
  },
  filters:{
    time(time){
      return time.split('T')[0];
    },
    setAvatar(avatar) {
      return "http://statics.zhuishushenqi.com" + avatar;
    },
    cover(cover){
      return "http://statics.zhuishushenqi.com" + cover;
    },
  },
  mounted(){
    this.axios('http://127.0.0.1:4000/data/book/'+this.$route.params.id).then((res) => {
      this.data = res.data.data;
      this.reviews = res.data.reviews;
      this.recommend = res.data.recommend;
    });
  },
  components:{backheader}
}
</script>

<style lang="css" scoped>
.book-info-section {
  position: relative;
  height: 100%;
  overflow: hidden;
  padding-top: 20px;
}
.book-info-section p{
  margin:0;
}

.book-detail {
  overflow: hidden;
  padding: 0 15px;
}

.book-detail .book-cover {
  display: inline-block;
  width: 64px;
  height: 92px;
  margin-right: 10px;
}

.fl {
  float: left;
}

.book-detail .book-desc {
  position: relative;
}

.book-detail .book-desc .book-title {
  color: #333;
  line-height: 1;
  margin: 3px 0 5px;
  font-weight: 500;
  font-size:16px;
}

.book-detail .book-desc .book-meta {
  font-size: 13px;
  line-height: 1.8;
}

.red {
  color: #ed424b;
}

.book-detail .book-desc .book-meta {
  font-size: 13px;
  line-height: 1.8;
}

.book-reader {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  text-align: center;
  padding: 10px 0;
  border-top: 1px solid #ebebeb;
}

.book-reader .reader-item {
  -webkit-box-flex: 1;
  -ms-flex: 1;
  flex: 1;
}

.book-reader .reader-item span.title {
  font-size: 12px;
  color: #999;
}

.book-reader .reader-item span {
  display: block;
  line-height: 1.5;
}

.book-intro.part {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
}

.book-intro {
  position: relative;
  padding: 10px 15px 0;
  font-size: 14px;
  line-height: 1.5;
  text-align: justify;
  border-top: 1px solid #ebebeb;
}

.book-menu {
  position: relative;
  margin-top: 10px;
  padding: 0 15px;
  border-top: 1px solid #ebebeb;
  border-bottom: 1px solid #ebebeb;
  box-sizing: border-box;
  overflow: hidden;
}

.book-menu a {
  display: block;
}

.book-menu .menu-title {
  font-size: 16px;
  line-height: 36px;
  font-weight: 400;
  color:#333;
}

.fl {
  float: left;
}

.book-menu .menu-content {
  position: relative;
  font-size: 12px;
  line-height: 36px;
  width: 70%;
  text-align: right;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  padding-right: 15px;
}

.gray {
  color: #969ba3;
}
.fr {
  float: right;
}
.split-dot {
  padding: 0 1px;
}

.review {
    position: relative;
    padding-left: 15px;
    overflow: hidden;
    border-bottom: 10px solid #f6f7f9;
}

.review ul{
    margin:0;
}

.review p{
    margin:0;
}
.review h2 {
    line-height: 1;
    padding-top: 10px;
    font-weight: 400;
    font-size: 16px;
    margin: 0;
}

.review .review-list {
    position: relative;
    overflow: hidden;
    padding: 0;
}

.review .review-item {
    position: relative;
    overflow: hidden;
    padding: 10px 0;
    font-size: 12px;
    border-bottom: 1px solid #ebebeb;
}

.review .review-item .avatar {
    position: absolute;
    top: 10px;
    left: 0;
    width: 40px;
    height: 40px;
}

.review .review-item .review-content {
    margin-left: 50px;
    padding-right: 15px;
    /* margin-top: -15px; */
}

.review .review-item .review-content .name {
    color: #a58d5e;
}

.review .review-item .review-content .title {
    line-height: 2;
    font-weight: 700;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
}

.review .review-item .review-content .time {
    color: #999;
}

.fr {
    float: right;
}

.review .review-item .review-content .content {
    line-height: 1.5;
}

.text-line-comm {
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}
.recommend {
    position: relative;
    overflow: hidden;
}

.recommend p{
    font-size:16px;
    margin:0;
}

ul li{
    list-style: none;
}
ul{
    padding:0;
}
.recommend h4 {
    font-weight: 400;
    font-size: 16px;
    color: #33373d;
    line-height: 1;
    border-left: 2px solid #ed424b;
    padding-left: 13px;
    margin: 10px 0;
}

.recommend h4 a {
    position: absolute;
    top: 12px;
    right: 15px;
    font-size: 13px;
}

.red {
    color: #ed424b;
}

.recommend h4 a::after {
    content: '>';
    display: inline-block;
    margin-left: 3px;
}

.recommend .recommend-list {
    position: relative;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
}

.recommend .recommend-list .recommend-item {
    -webkit-box-flex: 1;
    -ms-flex: 1;
    flex: 1;
    padding: 0 15px;
}

.recommend .recommend-list .cover {
    width: 60px;
    height: 80px;
}

.recommend-item p{
    width:100px;
    font-size: 10px;
}
.book-bar {
    /* position: fixed; */
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    height: 60px;
    background-color: #fff;
}

.book-bar p{
    margin: 0;
}

.book-bar a{
    text-decoration: none;
    color: inherit;
}

.book-bar .book-bar-item {
    display: block;
    -webkit-box-flex: 1;
    -ms-flex: 1;
    flex: 1;
    padding: 10px 0;
    font-size: 12px;
    color: #999;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
}

.book-bar .book-bar-item.read {
    font-size: 16px;
    color: #fff;
    background: #850f0f;
    line-height: 40px;
    border-top-color: #850f0f;
}

.book-bar .book-bar-content {
    text-align: center;
}
</style>
